1 package edu.jiangxin.apktoolbox.help.settings;
2
3 import edu.jiangxin.apktoolbox.swing.extend.EasyChildTabbedPanel;
4 import edu.jiangxin.apktoolbox.utils.Constants;
5
6 import javax.swing.*;
7 import java.awt.*;
8 import java.io.File;
9 import java.io.IOException;
10 import java.net.URI;
11 import java.net.URISyntaxException;
12
13 public class DependencyPathPanel extends EasyChildTabbedPanel {
14
15 private static final long serialVersionUID = 1L;
16
17 @Override
18 public void createUI() {
19 BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
20 setLayout(boxLayout);
21
22 createPathPanel(this, "Path of 7ZIP(e.g.\"C:/Program Files/7-Zip/7z.exe\")", "https://www.7-zip.org/", Constants.SEVEN_ZIP_PATH_KEY);
23 add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
24
25 createPathPanel(this, "Path of RAR(e.g.\"C:/Program Files/WinRAR/Rar.exe\")", "https://www.win-rar.com/", Constants.RAR_PATH_KEY);
26 add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
27
28 createPathPanel(this, "Path of RAR(e.g.\"C:/Program Files/WinRAR/WinRAR.exe\")", "https://www.win-rar.com/", Constants.WIN_RAR_PATH_KEY);
29 }
30
31 private void createPathPanel(JPanel panel, String label, String website, String confKey) {
32 JPanel pathPanel = new JPanel();
33 pathPanel.setLayout(new BoxLayout(pathPanel, BoxLayout.Y_AXIS));
34 panel.add(pathPanel);
35
36 JPanel firstLinePanel = new JPanel();
37 firstLinePanel.setLayout(new BoxLayout(firstLinePanel, BoxLayout.X_AXIS));
38
39 JLabel pathLabel = new JLabel(label);
40
41 JButton visitWebsiteButton = new JButton(bundle.getString("download.button"));
42
43 firstLinePanel.add(pathLabel);
44 firstLinePanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
45 firstLinePanel.add(visitWebsiteButton);
46 firstLinePanel.add(Box.createHorizontalGlue());
47
48 JPanel secondLinePanel = new JPanel();
49 secondLinePanel.setLayout(new BoxLayout(secondLinePanel, BoxLayout.X_AXIS));
50
51 JTextField pathTextField = new JTextField();
52 pathTextField.setText(conf.getString(confKey));
53
54 JButton pathButton = new JButton(bundle.getString("choose.file.button"));
55
56 secondLinePanel.add(pathTextField);
57 secondLinePanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
58 secondLinePanel.add(pathButton);
59
60 pathPanel.add(firstLinePanel);
61 pathPanel.add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
62 pathPanel.add(secondLinePanel);
63
64
65 visitWebsiteButton.addActionListener(e -> {
66 URI uri;
67 try {
68 uri = new URI(website);
69 Desktop.getDesktop().browse(uri);
70 } catch (URISyntaxException ex) {
71 logger.error("URISyntaxException", ex);
72 } catch (IOException ex) {
73 logger.error("IOException", ex);
74 }
75 });
76
77 pathButton.addActionListener(e -> {
78 JFileChooser jfc = new JFileChooser();
79 jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
80 jfc.setDialogTitle("select a file");
81 int ret = jfc.showDialog(new JLabel(), null);
82 if (ret == JFileChooser.APPROVE_OPTION) {
83 File file = jfc.getSelectedFile();
84 pathTextField.setText(file.getAbsolutePath());
85 conf.setProperty(confKey, pathTextField.getText());
86 }
87 });
88 }
89 }
90